package ui;

import services.SendServicempl;
import vo.Contract;
import vo.Send;

import java.util.List;
import java.util.Scanner;

public class SendLogin { //发货表页面
    static SendServicempl sendServicempl=new SendServicempl(); //对发货表操作的具体类
    static Scanner scanner=new Scanner(System.in);
    public static void Login(){
        System.out.println("1,添加数据");
        System.out.println("2,删除数据");
        System.out.println("3,修改数据");
        System.out.println("4,查询数据");
        System.out.println("5,查询所有数据");
        System.out.println("0,返回上一级");
        System.out.println("请输入你的选择");
        int fuctionNumbre=scanner.nextInt();
        switch (fuctionNumbre){
            case 1:
                if(add()){
                    System.out.println("添加成功");
                }else {
                    System.out.println("添加失败");
                }
            case 2:
                if(delet()){
                    System.out.println("删除完成");
                }else {
                    System.out.println("删除失败");
                }
            case 3:
                if(modify()){
                    System.out.println("修改完成");
                }else {
                    System.out.println("修改失败");
                }
            case 4:
                Send send=getcustombyid();
                System.out.println(send);
                break;
            case 5:
                List<Send> list=getall();
                for(Send send1:list){
                    System.out.println(send1);
                }
                break;
            case 0:
                System.out.println("返回");
        }
    }

    private static boolean add() {
        System.out.println("请输入商品id");
        int inventory_id=scanner.nextInt();
        System.out.println("请输入发货数量");
        int count=scanner.nextInt();
        System.out.println("请输入合同编号");
        int contract_id=scanner.nextInt();
        Send send=new Send(inventory_id,count,contract_id);
       return sendServicempl.add(send);
    }

    private static boolean delet() { //通过商品的id来找到要删除的信息
        System.out.println("请输入商品id");
        int inventory_id=scanner.nextInt();
        Send send=new Send(inventory_id);
        return sendServicempl.delete(send);
    }

    private static boolean modify() {//传入修改后的发货表来替换原来的,通过商品id来查找
        System.out.println("请输入商品id");
        int inventory_id=scanner.nextInt();
        System.out.println("请输入发货数量");
        int count=scanner.nextInt();
        System.out.println("请输入合同编号");
        int contract_id=scanner.nextInt();
        Send send=new Send(inventory_id,count,contract_id);
        return sendServicempl.modify(send);
    }

    private static Send getcustombyid() {//按照商品的id来查询
        System.out.println("请输入商品id");
        int inventory_id=scanner.nextInt();
        return sendServicempl.getcustombyid(inventory_id);
    }

    private static List<Send> getall() {
        return sendServicempl.getall();
    }
}
